#!/usr/bin/env ruby -wKU
#encoding: UTF-8

# for directory reading, make encoding compatible
Encoding.default_internal="UTF-8"

require 'logger'

$logger = Logger.new('log/rubycrawler.log')
#$logger.level = Logger::WARN
$logger.level = Logger::DEBUG

require 'backend/config/ConfigLoader'
require 'backend/crawler/TiebaCrawler'
require 'backend/data/TChapterWriter'
require 'backend/data/TChapterLoader'
require 'backend/model/Tieba'
  
configXml = "config/tieba.xml"

configLoader = TiebaConfig::ConfigLoader.new configXml
configLoader.load

novels = Model::Tieba.instance.novels
chpLoader = TiebaData::TChapterLoader.new
chpLoader.loadNovels(novels)

crawler = Crawler::TiebaCrawler.new
TiebaData::TChapterWriter.new crawler

require 'thwait'

threads = crawler.crawl
ThreadsWait.all_waits(*threads)
